package com.sghd.fight.robot.listenner;

import com.sghd.common.socket.anno.InSession;
import com.sghd.common.socket.anno.SocketCommand;
import com.sghd.common.socket.anno.SocketModule;
import com.sghd.fight.net.SocketEnum;
import com.sghd.fight.robot.core.Controller;
import com.sghd.pojo.fight.game.Result;
import com.sghd.pojo.fight.game.RoomVo;
import com.sghd.pojo.fight.game.RoundData;
import com.sghd.pojo.fight.game.SkillReport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.sghd.common.socket.session.SessionKeys.IDENTITY;

/**
 * @author wch
 * @date 2018-07-06 12:09
 * @desc 接收服务端推送
 **/
@Component
@SocketModule
public class PushReceiver {
    private Logger logger = LoggerFactory.getLogger(PushReceiver.class);
    @Autowired
    private Controller controller;

    @SocketCommand(SocketEnum.CONN)
    public void conn(@InSession(IDENTITY) long robotId, Result<String> response) {
        //服务器连接成功
        if (response.getCode() != 0) {
            logger.error("机器人[{}]连接失败", robotId);
        }
        controller.connSuccess(robotId);
    }
    @SocketCommand(SocketEnum._ROOM_INFO)
    public void roomInfo(@InSession(IDENTITY) long robotId, RoomVo roomVo) {
        controller.roomInfo(robotId, roomVo);
    }

    @SocketCommand(SocketEnum._START)
    public void roundStart(@InSession(IDENTITY) long robotId, RoundData roundData) {
        controller.roundStart(robotId, roundData);
    }

    @SocketCommand(SocketEnum._EXECUTE_SKILL)
    public void skillInfo(@InSession(IDENTITY) long robotId, SkillReport skillReport) {
        controller.skillInfo(robotId, skillReport);
    }
}
